
import http_request from "../../../Common/http_request";
import UserService from "../../services/userService";
import { mgrs, sers } from "../../system/OverallSystem ";
import PageBase from "./pageBase";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Fuwu extends PageBase {


    @property(cc.RichText)
    tishiLabel: cc.RichText = null

    private url = "https://changshazhise01-1254961065.cos.ap-guangzhou.myqcloud.com/zhise/oppo/agreement.json"

    onLoad() {

    }
    start() {

        http_request.getInstance().get(this.url, null, this.show.bind(this));

    }

    show(data) {
        console.log(data)
        let taht = this

        const jsonData: object = data;

        // console.log(jsonData)
        let str = ''

        for (const key in jsonData) {
            if (Object.prototype.hasOwnProperty.call(jsonData, key)) {
                const item = jsonData[key];
                let s = ''
                if (item.style && item.style.bold) {
                    if (item.test instanceof Array) {
                        let x = ''
                        for (const iterator of item.test) {
                            x += iterator
                        }
                        s = `<b>${x}</b>`
                    } else {
                        s = `<b>${item.text}</b>`

                    }
                } else {
                    if (item.test instanceof Array) {
                        let x = ''
                        for (const iterator of item.test) {
                            x += iterator
                        }
                        s = `${x}`
                    } else {
                        s = `${item.text}`
                    }
                }
                str += s
            }
        }

        str = str.replace(/company/gi, UserService.vivoSDKdata.zs_company)
        str = str.replace(/email/gi, 'email:' + UserService.vivoSDKdata.zs_postbox)
        str = str.replace(/app_name/gi, UserService.vivoSDKdata.zs_game_name)

        taht.tishiLabel.string = str
        taht.scheduleOnce(() => {
            taht.tishiLabel.node.parent.height = taht.tishiLabel.node.height
        })
    }

    // update (dt) {}
}
